import { httpRequest, uploadRequest } from '@/utils/request.js';

/**
 * @param {Object} 根据id查询字典值
 */
export function getDictList(id) {
  return httpRequest({ url: '/dataDictionary/value/' + id, method: 'GET' });
}

/**上传图片**/
export function uploadImg(url, data) {
  return uploadRequest({ url: '/oss/uploadFile', filePath: url, data });
}
/**删除图片**/
export function deleteImg(data) {
  return httpRequest({ url: '/oss/delete', method: 'GET', data });
}

/*根据省市县查询项目*/

export function getProjectData(data) {
  return httpRequest({
    url: `/energy-station/listCheckedData`,
    method: 'GET',
    data,
  });
}
/**
 * @param {Object} 根据id查询公司信息
 */
export function getCompanyInfo(id) {
  return httpRequest({ url: `/company/${id}`, method: 'GET' });
}

/**查询公司*/
export function queryCompany(data) {
  return httpRequest({ url: '/company/list', method: 'GET', data: data });
}

/**添加或保存公司信息**/
export function addOrSaveCompany(data) {
  return httpRequest({ url: '/company/save', method: 'POST', data: data });
}

/**查询能源站**/
export function queryEnergyStation(id, data) {
  return httpRequest({
    url: `/energy-station/allList/${id}`,
    method: 'GET',
    data: data,
  });
  // return httpRequest({ url:'/energy-station/list',method:"GET",data:data })
}

/**添加或保存能源站**/
export function addSaveEnergyStation(data) {
  return httpRequest({
    url: '/energy-station/save',
    method: 'POST',
    data: data,
  });
}

/**生成唯一标识用于能源站图片上传 */
export function generateId() {
  return httpRequest({
    url: '/generateId',
    method: 'GET',
  });
}

/**
 * @param {Object} data
 * 根据id查询能源站
 */
export function getEnergyStationInfo(id, data) {
  return httpRequest({
    url: `/energy-station/${id}`,
    method: 'GET',
    data: data,
  });
}

/**添加修改锅炉**/

export function addOrEditBoiler(data) {
  return httpRequest({ url: '/boiler/save', method: 'POST', data: data });
}

/**查询锅炉**/

export function quergyBoiler(stationId, data) {
  return httpRequest({
    url: `/boiler/allList/${stationId}`,
    method: 'GET',
    data: data,
  });
  // return httpRequest({ url:'/boiler/list',method:"GET",data:data })
}
/**查询锅炉信息**/
export function getBoilerInfo(id, data) {
  return httpRequest({ url: '/boiler/' + id, method: 'GET', data: data });
}

/**
 * 查询新能源
 */
export function quergyNewEnergy(id, data) {
  return httpRequest({
    url: `/newEnergy/allList/${id}`,
    method: 'GET',
    data: data,
  });
}
/**添加或保存新能源**/

export function addSaveNewEnergy(data) {
  return httpRequest({ url: '/newEnergy/save', method: 'POST', data: data });
}
/**查询新能源信息**/
export function getNewEnergyInfo(id, data) {
  return httpRequest({ url: `/newEnergy/${id}`, method: 'GET', data: data });
}

/**
 * 查询热表
 */
export function queryHeatMeter(stationId, data) {
  return httpRequest({
    url: `/heatmater/allList/${stationId}`,
    method: 'GET',
    data: data,
  });
}

/**查询热表信息**/
export function getHeatMeterInfo(id, data) {
  return httpRequest({ url: `/heatmater/${id}`, method: 'GET', data: data });
}
/**
 * 添加修改热表
 */

export function addSaveHeatMeter(data) {
  return httpRequest({ url: '/heatmater/save', method: 'POST', data: data });
}

function objectToQueryString(obj) {
  return Object.entries(obj)
    .filter(
      ([_, value]) => value !== null && value !== undefined && value !== ''
    ) // 过滤掉空值或未定义值
    .map(
      ([key, value]) =>
        `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
    ) // 编码并拼接键值对
    .join('&'); // 使用&连接所有的键值对
}

/**复制**/
export function copyData(type, data) {
  let url = '';
  if (type == 'boiler') {
    url = '/boiler/copy';
  } else if (type == 'newEnergy') {
    url = '/newEnergy/copy';
  } else {
    url = '/heatmater/copy';
  }
  const params = objectToQueryString(data);
  return httpRequest({ url: `${url}?${params}`, method: 'POST' });
}
